package com.dounine.test.thread;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

public class HostUtil {

	public static boolean checkCollect(String host,int port){
		Socket socket = null;
		boolean pass = true;
		try {
			socket = new Socket();
			socket.connect(new InetSocketAddress(host,port),1000);
		} catch (UnknownHostException e) {
			System.err.println("主机地址不识别");
			pass = false;
		}catch (SocketTimeoutException to) {
			System.err.println("连接超时");
			pass = false;
		} catch (IOException e) {
			pass = false;
			e.printStackTrace();
		} finally {
			if(!socket.isClosed()){
				try {
					socket.close();
				} catch (IOException e) {
					pass = false;
					e.printStackTrace();
				}
			}
		}
		return pass;
	}
}
